package com.ruoyi.group.service.impl;

import com.ruoyi.group.domain.RepairOrderTransfer;
import com.ruoyi.group.domain.RpRepairOrder;
import com.ruoyi.group.domain.dto.RepairOrderTransferDto;
import com.ruoyi.group.mapper.RepairOrderMapper;
import com.ruoyi.group.mapper.RepairOrderTransferMapper;
import com.ruoyi.group.service.RepairOrderTransferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

/**
 * @author: admin  <br/>
 * Date: 2022/3/12:10:28  <br/>
 * Description:
 */
@Service
public class RepairOrderTransferServiceImpl implements RepairOrderTransferService {
    @Autowired
    private RepairOrderTransferMapper repairOrderTransferMapper;
    @Autowired
    private RepairOrderMapper repairOrderMapper;
    @Override
    public List<RepairOrderTransfer> selectTransferList(RepairOrderTransfer repairOrderTransfer) {

        return repairOrderTransferMapper.selectTransferList(repairOrderTransfer);
    }

    @Override
    public RepairOrderTransferDto findByOrderNo(String orderNo) {
        RpRepairOrder repairOrder=repairOrderMapper.findByOrderNo(orderNo);
        RepairOrderTransfer repairOrderTransfer = repairOrderTransferMapper.findByOrderNo(orderNo);

        RepairOrderTransferDto repairOrderTransferDto = new RepairOrderTransferDto();
        repairOrderTransferDto.setOrderNo(orderNo);
        repairOrderTransferDto.setRoType(repairOrder.getRepairTypeV2());
        repairOrderTransferDto.setRoDescription(repairOrder.getRepairDescription());
        repairOrderTransferDto.setCreateTime(repairOrder.getCreateTime());
        repairOrderTransferDto.setRoStatus(repairOrder.getRepairStatus());
        repairOrderTransferDto.setAvatar(repairOrder.getRepairPicture());

        repairOrderTransferDto.setDeptSumbitP(repairOrderTransfer.getDeptSumbitP());
        repairOrderTransferDto.setDescribe(repairOrderTransfer.getDescribe());
        repairOrderTransferDto.setTransferTime(repairOrderTransfer.getCreateTime());
        return repairOrderTransferDto;
    }

    @Override
    public int updateTansfer(String orderNo, String deptName, String nickName) {
        int i = repairOrderTransferMapper.updateTansfer(deptName,nickName,orderNo);
        int j =repairOrderMapper.updateTansfer(orderNo);
        if(i>0 && j>0){
            return  1;
        }
        return -1;
    }

    @Override
    public int updateRefuse(String orderNo, String deptName, String nickName) {
        int i = repairOrderTransferMapper.updateRefuse(orderNo);
        int j =repairOrderMapper.updateRefuse(orderNo);
        if(i>0 && j>0){
            return  1;
        }
        return -1;
    }
}
